// pages/examhome/examhome.js
var app = getApp();
Page({

  data: {
    passf: 0,
    time: 0,
    num: 0,
    everyf: 1,
    use_title: "",
    training_qids: ""
  },

  onLoad: function (options) {
    console.log(options);
    this.setData({
      id: options.id
    })
    this.onQuery(options.id);
  },
  onQuery: function(id) {
    let that = this;

    const db = wx.cloud.database()
    db.collection('exam').doc(id).get().then(res => {
      console.log('[数据库] [查询记录] 成功: ', res)
      that.setData({
        _id: res.data._id,
        time: res.data.time || 20,
        num: res.data.number || 10 ,
        use_title: res.data.name || '',
        passf: res.data.passf || 80
      });
    })
  },
  onReady: function () {

  },

  onShow: function () {

  },
  examGo:function (e) {
    let time = this.data.time;
    let passf = this.data.passf;
    let num = this.data.num;

    wx.redirectTo({
      url: "../exam/exam?examid="+this.data.id+"&continued=1&passf=" + passf + "&time=" + time + "&training_qids=0&nums=" + num
    });
  },

  defaultGo: function(){
    this.examGo();
  }
})